package com.ruoyi.web.zangchat.controller;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.text.Convert;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.zangchat.domain.ChatSysConfigs;
import com.ruoyi.web.zangchat.service.IChatSysConfigsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商城总配置Controller
 * 
 * @author ruoyi
 * @date 2020-07-19
 */
@Controller
@RequestMapping("/zangchat/chatsysconfigs")
public class ChatSysConfigsController extends BaseController
{
    private String prefix = "zangchat/chatsysconfigs";

    @Autowired
    private IChatSysConfigsService chatSysConfigsService;

    @RequiresPermissions("zangchat:chatsysconfigs:view")
    @GetMapping()
    public String chatsysconfigs()
    {
        return prefix + "/chatsysconfigs";
    }

    /**
     * 查询商城总配置列表
     */
    @RequiresPermissions("zangchat:chatsysconfigs:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ChatSysConfigs chatSysConfigs)
    {
        startPage();
        return getDataTable(chatSysConfigsService.list(new QueryWrapper<ChatSysConfigs>(chatSysConfigs)));
    }

    /**
     * 导出商城总配置列表
     */
    @RequiresPermissions("zangchat:chatsysconfigs:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChatSysConfigs chatSysConfigs)
    {
        List<ChatSysConfigs> list = chatSysConfigsService.list(new QueryWrapper<>());
        ExcelUtil<ChatSysConfigs> util = new ExcelUtil<ChatSysConfigs>(ChatSysConfigs.class);
        return util.exportExcel(list, "chatsysconfigs");
    }

    /**
     * 新增商城总配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商城总配置
     */
    @RequiresPermissions("zangchat:chatsysconfigs:add")
    @Log(title = "商城总配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChatSysConfigs chatSysConfigs)
    {
        return toAjax(chatSysConfigsService.save(chatSysConfigs));
    }

    /**
     * 修改商城总配置
     */
    @GetMapping("/edit/{configId}")
    public String edit(@PathVariable("configId") Integer configId, ModelMap mmap)
    {
        ChatSysConfigs chatSysConfigs = chatSysConfigsService.getById(configId);
        mmap.put("chatSysConfigs", chatSysConfigs);
        return prefix + "/edit";
    }

    /**
     * 修改保存商城总配置
     */
    @RequiresPermissions("zangchat:chatsysconfigs:edit")
    @Log(title = "商城总配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChatSysConfigs chatSysConfigs)
    {
        return toAjax(chatSysConfigsService.updateById(chatSysConfigs));
    }

    /**
     * 删除商城总配置
     */
    @RequiresPermissions("zangchat:chatsysconfigs:remove")
    @Log(title = "商城总配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chatSysConfigsService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
    }
}
